import {
	showToast
} from "@/utils/modal.js"
// 本地
// let baseApi = 'http://k3n3211190.51vip.biz'
// 测试
// let baseApi = 'http://106.52.200.181:10010'
// 正式
let baseApi = 'http://hmzf-lg.yuemandata.com'
let baseUrl = "";
// #ifdef H5
baseUrl = process.env.VITE_APP_BASE_API;
// #endif
baseUrl = baseUrl ? baseUrl : baseApi
const request = (options = {}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + '/api/entry',
			method: options.type || 'GET',
			data: options.data || {},
			header: options.header || {},
			success: (res) => {
				if (res.data.status != 'SUCCESS') {
					uni.hideToast();
					setTimeout(() => {
						showToast(res.data.message || "请求失败")
					}, 10)
					reject(res)
				} else {
					resolve(res.data);
				}
			},
			fail: (err) => {
				// 无网络提示
				let str = "No address associated with hostname";
				if (err.errMsg.indexOf(str) > -1) {
					showToast("请连接网络")
				}
				reject(err)
			}
		})
	});
}

export default {
	request
}